#!/bin/python 
import struct
import  matplotlib.pyplot as plt
class genXY:
    def __init__(self,x=1280,y=1024,cols=4,rows=4):
        self.x=x
        self.y=y
        self.rows=rows
        self.cols=cols
        self.x_step=self.x/self.cols
        self.y_step=self.y/self.rows
        self.x_coord=[]
        self.y_coord=[]
        self.kvs=[0x1E,0x1f,0x20,0x29,0x21,0x22,0x23,0x2a,0x24,0x25,0x26,0x28,0x04,0x27,0x05,0x06]
        print"%02x" % (x/256)
        print"%02x" % (x%256)
    def genCoord(self):       
        for i in range(0,self.rows+1):
            self.x_coord.append(i*self.x_step)
            #print"%04x" %x_coord[i]
        for i in range(0,self.cols+1):
            self.y_coord.append(i*self.y_step)
            #print"%04x" %y_coord[i]
        for iy in range(0,self.cols+1):
            for ix in range(0,self.rows+1):
                print"(%d,%d)=(%04x %04x) " %(ix,iy,self.x_coord[ix], self.y_coord[iy]),  
            print ''
        pos=[]
        dir=0
        for iy in range(0,self.cols):
            for ix in range(0,self.rows):
                if(dir == 1):

                    print"%04x %04x %04x %04x %04x %04x %04x %04x" %(self.x_coord[ix], self.y_coord[iy] ,self.x_coord[ix+1], self.y_coord[iy] ,self.x_coord[ix+1], self.y_coord[iy+1] ,self.x_coord[ix], self.y_coord[iy+1] )
                    pos.append([self.x_coord[ix], self.y_coord[iy] ,self.x_coord[ix+1], self.y_coord[iy] ,self.x_coord[ix+1], self.y_coord[iy+1] ,self.x_coord[ix], self.y_coord[iy+1]] )
                else:
                    print"%04x %04x %04x %04x %04x %04x %04x %04x" %(self.x_coord[ix], self.y_coord[iy] ,self.x_coord[ix], self.y_coord[iy+1] ,self.x_coord[ix+1], self.y_coord[iy+1] ,self.x_coord[ix+1], self.y_coord[iy] )
                    pos.append([self.x_coord[ix], self.y_coord[iy] ,self.x_coord[ix], self.y_coord[iy+1] ,self.x_coord[ix+1], self.y_coord[iy+1] ,self.x_coord[ix+1], self.y_coord[iy]] )

        rs=0x30	
        for i in range(0, len(pos)):
            if i == 0:
                rs = 0x31
            else:
                rs = 0x30
                
            raw_cmd =  "FE 00 %02x %02x 04 " % (rs,self.kvs[i])
            print raw_cmd ,
            for j in range(0,8):
                print"%02x %02x "  %(pos[i][j]%256, pos[i][j]/256),
            print ''
        for i in range(0, len(pos)):
            j=0
            while(j<8):
                print"(%04d %04d)"  %(pos[i][j], pos[i][j+1]),
                j += 2
            print ' '
            
if __name__ == '__main__':
    genxy = genXY(1280,1024,2,2)
    genxy.genCoord()